#include "btform.h"
#include<QDebug>
#include "ui_btform.h"

BtForm::BtForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::BtForm)
{
    ui->setupUi(this);

    //设置动画效果
    setLabelAnimation(animationLine1,ui->lineLabel1,1500,4,0);
    setLabelAnimation(animationLine2,ui->lineLabel2,1600,10,0);
    setLabelAnimation(animationLine3,ui->lineLabel3,1700,16,0);
    setLabelAnimation(animationLine4,ui->lineLabel4,1800,22,0);
    //隐藏动画
    hideAnimation();


}

BtForm::~BtForm()
{
    delete ui;
}

void BtForm::setIconAndTextAndId(QString iconURL, QString text,int pageId){
    //修改图标
    ui->btIconLabel->setPixmap(iconURL);
    //修改内容
    ui->btTextLabel->setText(text);
    //设置id
    this->_pageId = pageId;
}

void BtForm::mousePressEvent(QMouseEvent *event)
{
    //避免编译器触发警告
    (void)event;

    //点击修改背景颜色
    setBackground();

    //当按钮按下的时候，修改右边bodyRight的Page界面
    //发送信号
    emit btClick(_pageId);
   // qDebug() << "hello";
}

//获取当前控件对应的stackWidget页面索引
int BtForm::getPageId()
{
    return _pageId;
}

//清楚点击后留存的颜色
void BtForm::clearBackground()
{
    ui->BtStyle->setStyleSheet("#BtStyle:hover{background:#D8D8D8;}");
}

//设置动画
void BtForm::setLabelAnimation(QPropertyAnimation* animation, QLabel* label,int time, int x, int y)
{
    animation = new QPropertyAnimation(label, "geometry", this);
    animation->setDuration(time);//持续时间
    animation->setKeyValueAt(0,QRect(x,y,2,15));
    animation->setKeyValueAt(0.5,QRect(x,y + 15,2,15));
    animation->setKeyValueAt(1,QRect(x,y,2,15));
    animation->setLoopCount(-1);
    animation->start();
}

//显示动画
void BtForm::showAnimation()
{
    ui->lineBox->show();
}

//隐藏动画
void BtForm::hideAnimation()
{
    ui->lineBox->hide();
}

void BtForm::setBackground()
{
    //点击修改背景颜色
    ui->BtStyle->setStyleSheet("#BtStyle{background-color:rgb(30, 206, 154);}");
}
